const addMainMenu = {
  state: {
    menu: []
  },
  mutations: {
    addMainMenu: (state, menu) => {
      state.menu.forEach((item, index) => {
        if (item.path === menu.path) {
          // 如果已经存在，删除掉，以便更新
          state.menu.splice(index, 1)
        }
      })
      // 放在最前面
      state.menu.unshift(menu)
    },
    deleteMainMenu: (state, path) => {
      state.menu.forEach((item, index) => {
        if (item.path === path) {
          // 删除掉
          state.menu.splice(index, 1)
        }
      })
    },
    deleteMainMenuAll: (state) => {
      state.menu = []
    }
  }
}

export default addMainMenu
